//
//  ArrayModel.swift
//  Pods
//
//  Created by eme on 2017/3/28.
//
//

import Foundation
import SwiftyJSON
import ModelProtocol

class ArrayModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kArraySendtypeKey: String = "sendtype"
    internal let kArrayPdnameKey: String = "pdname"
    internal let kArrayPdidKey: String = "pdid"
    internal let kArrayBdidKey: String = "bdid"
    internal let kArrayPsfnameKey: String = "psfname"
    internal let kArrayImg1Key: String = "img1"
    internal let kArrayDetailtotalKey: String = "detailtotal"
    internal let kArraySkuidKey: String = "skuid"
    internal let kArrayPsvalueKey: String = "psvalue"
    internal let kArrayPsfname2Key: String = "psfname2"
    internal let kArrayOrderidKey: String = "orderid"
    internal let kArrayDetailstatusKey: String = "detailstatus"
    internal let kArrayDetailidKey: String = "detailid"
    internal let kArrayPsvalue2Key: String = "psvalue2"
    internal let kArrayPdtypeKey: String = "pdtype"
    internal let kArrayShpriceKey: String = "shprice"
    internal let kArrayDetailrnumberKey: String = "detailrnumber"
    
    
    // MARK: 属性
    var sendtype: String
    var pdname: String
    var pdid: Int
    var bdid: String
    var psfname: String
    var img1: String
    var detailtotal: Int
    var skuid: Int
    var psvalue: String
    var psfname2: String
    var orderid: String
    var detailstatus: String
    var detailid: Int
    var psvalue2: String
    var pdtype: String
    var shprice: Double
    var detailrnumber: Int
    var standard:String{
        get{
            if psfname == ""
            {
                return ""
            }
            else if psfname2 == ""
            {
                if psvalue != ""{
                    return self.psfname + ":" + self.psvalue
                }else{
                    return self.psfname
                }
                
            }
            else
            {
                if self.psvalue != "" && psvalue2 != ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue == "" && psvalue2 != ""{
                    
                    return self.psfname + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue != "" && psvalue2 == ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2
                    
                }else{
                    return self.psfname + ";" + self.psfname2
                    
                }
            }
            
        }
        
    }
    
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        
        sendtype = json[kArraySendtypeKey].stringValue
        pdname = json[kArrayPdnameKey].stringValue
        pdid = json[kArrayPdidKey].intValue
        bdid = json[kArrayBdidKey].stringValue
        psfname = json[kArrayPsfnameKey].stringValue
        img1 = json[kArrayImg1Key].stringValue
        detailtotal = json[kArrayDetailtotalKey].intValue
        skuid = json[kArraySkuidKey].intValue
        psvalue = json[kArrayPsvalueKey].stringValue
        psfname2 = json[kArrayPsfname2Key].stringValue
        orderid = json[kArrayOrderidKey].stringValue
        detailstatus = json[kArrayDetailstatusKey].stringValue
        detailid = json[kArrayDetailidKey].intValue
        psvalue2 = json[kArrayPsvalue2Key].stringValue
        pdtype = json[kArrayPdtypeKey].stringValue
        shprice = json[kArrayShpriceKey].doubleValue
        detailrnumber = json[kArrayDetailrnumberKey].intValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(sendtype as AnyObject, forKey: kArraySendtypeKey)
    
        dictionary.updateValue(pdname as AnyObject, forKey: kArrayPdnameKey)
    
        dictionary.updateValue(pdid as AnyObject, forKey: kArrayPdidKey)

        dictionary.updateValue(bdid as AnyObject, forKey: kArrayBdidKey)
    
        dictionary.updateValue(psfname as AnyObject, forKey: kArrayPsfnameKey)
    
        dictionary.updateValue(img1 as AnyObject, forKey: kArrayImg1Key)
    
        dictionary.updateValue(detailtotal as AnyObject, forKey: kArrayDetailtotalKey)
    
        dictionary.updateValue(skuid as AnyObject, forKey: kArraySkuidKey)
    
        dictionary.updateValue(psvalue as AnyObject, forKey: kArrayPsvalueKey)
    
        dictionary.updateValue(psfname2 as AnyObject, forKey: kArrayPsfname2Key)
    
        dictionary.updateValue(orderid as AnyObject, forKey: kArrayOrderidKey)
    
        dictionary.updateValue(detailstatus as AnyObject, forKey: kArrayDetailstatusKey)
    
        dictionary.updateValue(detailid as AnyObject, forKey: kArrayDetailidKey)
    
        dictionary.updateValue(psvalue2 as AnyObject, forKey: kArrayPsvalue2Key)
    
        dictionary.updateValue(pdtype as AnyObject, forKey: kArrayPdtypeKey)
    
        dictionary.updateValue(shprice as AnyObject, forKey: kArrayShpriceKey)
    
        dictionary.updateValue(detailrnumber as AnyObject, forKey: kArrayDetailrnumberKey)
        
        
        return dictionary
    }
    
    
}
